package com.zx.crowdfunding.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zx.crowdfunding.entity.po.MemberPO;
import com.zx.crowdfunding.entity.po.MemberPOExample;
import com.zx.crowdfunding.entity.po.MemberPOExample.Criteria;
import com.zx.crowdfunding.mapper.MemberPOMapper;
import com.zx.crowdfunding.service.api.MemberService;

/**
 * 会员 - Service接口实现类
 * @author 郑雪
 * @date 2021-12-29
 */
@Service
// 针对查询操作设置事务只读属性
@Transactional(readOnly = true)
public class MemberServiceImpl implements MemberService {

	/**
	 * 会员Mapper接口
	 */
	@Autowired
	private MemberPOMapper memberPOMapper;

	@Override
	public MemberPO getMemberPOByLoginAcct(String loginacct) {
		
		// 1.创建Example对象
		MemberPOExample example = new MemberPOExample();
		
		// 2.创建Criteria对象
		Criteria criteria = example.createCriteria();
		
		// 3.封装查询条件
		criteria.andLoginacctEqualTo(loginacct);
		
		// 4.执行查询
		List<MemberPO> list = memberPOMapper.selectByExample(example);
		
		// 5.返回结果
		if(list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
	public void saveMember(MemberPO memberPO) {
		memberPOMapper.insertSelective(memberPO);
	}
	
}
